package CCRMClient.GUI;

import java.awt.Color;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;

import CCRMClient.ClientStart;
import Common.SERVER_COMMANDS;

/**
 * This class implements change customer status  screen panel
 * @author Ola
 *
 */
public class ChangeCustomerStatusScreen extends JPanel {
	
	private JLabel lblChangeCistomerStatus;
	private JLabel lblCustomerID;
	private JTextField textCustomerId;
	private JButton btnChangeStatus;
	private JButton btnCancel;
	/**
	 *  Create add change customer status screen.
	 */
	public ChangeCustomerStatusScreen(){
		initialize();
	}
	
	private void initialize() {
		setSize(689, 492);
		setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
		setBackground(Color.WHITE);
		setLayout(null);
		add(getLblChangeCistomerStatus());
		add(getLblCustomerID());
		add(getTextCustomerId());
		add(getBtnChangeStatus());
		add(getBtnCancel());
	}
	

	JLabel getLblChangeCistomerStatus() {
		if (lblChangeCistomerStatus == null) {
			lblChangeCistomerStatus = new JLabel("Change Customer Status");
			lblChangeCistomerStatus.setHorizontalAlignment(SwingConstants.CENTER);
			lblChangeCistomerStatus.setForeground(Color.BLACK);
			lblChangeCistomerStatus.setFont(new Font("David", Font.BOLD, 26));
			lblChangeCistomerStatus.setBounds(68, 54, 614, 27);
		}
		return lblChangeCistomerStatus;
	}
	
JLabel getLblCustomerID(){
		
		if(lblCustomerID==null){
			lblCustomerID=new JLabel("Customer ID");
			lblCustomerID.setFont(new Font("David", Font.BOLD, 20));
			lblCustomerID.setBounds(104, 125, 164, 29);
		}
		return lblCustomerID;
		
	}

JTextField getTextCustomerId() {
	if (textCustomerId == null) {
		textCustomerId = new JTextField();
		textCustomerId.setColumns(10);
		textCustomerId.setBackground(SystemColor.menu);
		textCustomerId.setBounds(323, 130, 251, 20);
	}
	
	return textCustomerId ;
}
	
JButton getBtnCancel(){
	if (btnCancel == null) {
		btnCancel = new JButton("Cancel");
		btnCancel.addActionListener(new BtnCancelActionListener());
		btnCancel.setFont(new Font("Tahoma", Font.BOLD, 12));
		btnCancel.setBounds(311, 419, 207, 23);
}
	return btnCancel;
	
}

JButton getBtnChangeStatus(){
	if (btnChangeStatus == null) {
		btnChangeStatus = new JButton("Change Status");
		btnChangeStatus.addActionListener(new BtnChangeStatusActionListener());
		btnChangeStatus.setFont(new Font("Tahoma", Font.BOLD, 12));
		btnChangeStatus.setBounds(83, 419, 175, 23);
}
	return btnChangeStatus;
	
}
/**
 * This inner class implements event listener for add cancel button
 * @author Ola
 *
 */
private class BtnCancelActionListener implements ActionListener {
	public void actionPerformed(ActionEvent arg0) {
		ClientStart.panelSwicher(new CustomerManage());
	}
}
/**
 * This inner class implements event listener for change status button
 * @author Ola
 *
 */
private class BtnChangeStatusActionListener implements ActionListener {
	public void actionPerformed(ActionEvent arg0) {
		try {
			String Id=textCustomerId.getText();
			if(Id.isEmpty())throw new NullPointerException();
			
			try {
				ClientStart.client.handleMessageFromGUI(SERVER_COMMANDS.UPDATE_CUSTOMER_STATUS,Id); //ClientCustomerManagement.SearchCustomerByCondition( SERVER_COMMANDS.GET_CUSTOMER_BY_CONDITION,search));
			} catch (IOException exp) {
				JOptionPane.showMessageDialog(null, "Lost connection with server", "Communication Error", JOptionPane.ERROR_MESSAGE);
				ClientStart.quitApp();
			}
		
			
		}catch (NullPointerException exp) {
			JOptionPane.showMessageDialog(null, "All fields are mandatory", "Change Customer Status", JOptionPane.INFORMATION_MESSAGE);
		
	}
}
}
}


